<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='Comments',active='comments'">
<header th:replace="admin/fragments/header::headerFragment(${title},${active})"></header>

<body class="fixed-left">
    <div id="wrapper">
        <div th:replace="admin/fragments/header::header-body"></div>
        <div class="content-page">
            <div class="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12">
                            <h4 class="page-title">Comments</h4>
                        </div>
                        <div class="col-md-12">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>Content</th>
                                        <th>Commentor</th>
                                        <th>Time</th>
                                        <th>E-mail</th>
                                        <th>Address</th>
                                        <th>Status</th>
                                        <th>Operation</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <th:block th:each="comment : ${comments.list}">
                                        <tr th:attr="cid=${comment.coid}">
                                            <td>
                                                <a th:href="@{${commons.site_url('/blog/article/')}+${comment.cid}+'#comments-content'}"
                                                    target="_blank" th:utext="${commons.article(comment.content)}"></a>
                                            </td>
                                            <td th:text="${comment.author}"></td>
                                            <td th:text="${commons.fmtdate(comment.created, 'yyyy-MM-dd HH:mm:ss')}">
                                            </td>
                                            <td th:text="${comment.email}"></td>
                                            <td><a th:href="@{${comment.url}}" target="_blank"
                                                    th:text="${comment.url}"></a>
                                            </td>
                                            <td>
                                                <th:block th:if="${comment.status == 'approved'}">
                                                    <span class="label label-success">Passed</span>
                                                </th:block>
                                                <th:block th:if="${comment.status == 'not_audit'}">
                                                    <span class="label label-default">Unverified</span>
                                                </th:block>
                                            </td>
                                            <td>
                                                <th:block th:if="${comment.status == 'not_audit'}">
                                                    <a href="javascript:void(0)"
                                                        th:onclick="'updateStatus('+${comment.coid}+');'"
                                                        class="btn btn-success btn-sm waves-effect waves-light m-b-5">
                                                        <i class="fa fa-check-square-o"></i>
                                                        <span>Pass</span>
                                                    </a>
                                                </th:block>
                                                <a href="javascript:void(0)"
                                                    th:onclick="'delComment('+${comment.coid}+');'"
                                                    class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                                    <i class="fa fa-trash-o"></i>
                                                    <span>Delete</span>
                                                </a>
                                            </td>
                                        </tr>
                                    </th:block>
                                </tbody>
                            </table>
                            <div th:replace="comm/macros :: pageAdminNav(${comments})"></div>
                        </div>
                    </div>
                    <div th:replace="admin/fragments/footer :: footer-content"></div>
                </div>
            </div>
        </div>
    </div>
    <div th:replace="admin/fragments/footer :: footer"></div>
    <script type="text/javascript">
        /*<![CDATA[*/
        var tale = new $.tale();

        function delComment(coid) {
            tale.alertConfirm({
                title: 'Sure to delete?',
                then: function () {
                    tale.post({
                        url: '/admin/comments/delete',
                        data: { coid: coid },
                        success: function (result) {
                            if (result && result.code == 'success') {
                                tale.alertOkAndReload('Successful!');
                            } else {
                                tale.alertError(result.msg || 'Failed!');
                            }
                        }
                    });
                }
            });
        }

        function updateStatus(coid) {
            tale.alertConfirm({
                title: 'Sure to pass?',
                then: function () {
                    tale.post({
                        url: '/admin/comments/status',
                        data: { coid: coid, status: "approved" },
                        success: function (result) {
                            if (result && result.code == 'success') {
                                tale.alertOkAndReload('Successful!');
                            } else {
                                tale.alertError(result.msg || 'Failed!');
                            }
                        }
                    });
                }
            });
        }
    /*]]>*/
    </script>
</body>

</html>